;password generation procedure for Casino Games (Sega Master System) ;contact : tigrou dot ind at gmail dot com ;account name start at C90E, and is encoded in ascii (A = 0x41, Z = 0x5A, ...) (10 bytes) ;money start at C927, and is encoded in BCD (eg: 10 20 95 00 for $00952010) (4 bytes) ;generated account number start at C91B, first encoded as unpacked BCD (eg : 04 02 03 04 08 09 00 01 05 09) (10 bytes) ;the account is then converted to ascii for display (eg : 34 32 33 34 38 39 30 31 35 39) ;account[7] = rand(0, 9) ;account[8] = money[0] ;account[2] = money[1] ;account[4] = money[2] ;account[1] = money[3] ;account[6] = money[4] ;account[9] = money[5] ;account[0] = money[6] ;account[5] = name_checksum ;account[3] = final_checkum ;name_checksum = (sum(name) + rand) % 256 % 10 ;final_checkum = (circular_left_shift(account) + sum(account)) % 256 % 10 ;main routine 00004ED3: LD A,0Ah 00004ED5: CALL 11CBh ;generate a random number between 0-9 00004ED8: LD (C922h),A ;random number => account 08 00004EDB: LD HL,C92Ah 00004EDE: CALL 4F27h 00004EE1: LD (C923h),A ;money 1st digit => account 09 00004EE4: CALL 4F2Eh 00004EE7: LD (C91Dh),A ;money 2nd digit => account 03 00004EEA: DEC HL 00004EEB: CALL 4F27h 00004EEE: LD (C91Fh),A ;money 3rd digit => account 05 00004EF1: CALL 4F2Eh 00004EF4: LD (C91Ch),A ;money 4th digit => account 02 00004EF7: DEC HL 00004EF8: CALL 4F27h 00004EFB: LD (C921h),A ;money 5th digit => account 07 00004EFE: CALL 4F2Eh 00004F01: LD (C924h),A ;money 6th digit => account 10 00004F04: DEC HL 00004F05: CALL 4F27h 00004F08: LD (C91Bh),A ;money 7th digit => account 01 00004F0B: CALL 4F3Dh ;compute crc on name 00004F0E: CALL 4F31h ;add random value generated previously 00004F11: LD (C920h),A ;crc name => account 06 00004F14: CALL 4F4Dh ;compute crc on all previously generated account digits (except 4th digit) 00004F17: LD (C91Eh),A ;crc account => account 04 00004F1A: LD HL,C91Bh ;convert all generated digits to ascii 00004F1D: LD B,0Ah 00004F1F: LD A,(HL) 00004F20: ADD 30h ;+ 0x30 00004F22: LD (HL),A 00004F23: INC HL 00004F24: DJNZ -07h 00004F26: RET ;extract nibble, add random digit (0-9), then modulo 10 00004F27: LD A,(HL) 00004F28: RRCA ;swap nibbles (eg : 0x25 => 0x52) 00004F29: RRCA ; 00004F2A: RRCA ; 00004F2B: RRCA ; 00004F2C: JR +01h 00004F2E: LD A,(HL) 00004F2F: AND 0Fh ;extract nibble (eg : 0x52 => 0x02) 00004F31: LD C,A 00004F32: LD A,(C922h) ;add randomizer (0-9) 00004F35: ADD C ; 00004F36: SUB 0Ah ;modulo 10 00004F38: JR NC,-04h ; 00004F3A: ADD 0Ah ; 00004F3C: RET ;crc for name and account number 00004F3D: XOR A ;compute name crc 00004F3E: LD HL,C90Eh 00004F41: LD B,0Ah 00004F43: CALL 4F48h ;sum each character 00004F46: JR -12h 00004F48: ADD (HL) ;crc summing subroutine 00004F49: INC HL 00004F4A: DJNZ -04h 00004F4C: RET 00004F4D: XOR A ;compute account crc 00004F4E: LD HL,C91Bh 00004F51: LD B,03h 00004F53: CALL 4F6Ch ;xor crc for digits 1-3 00004F56: INC HL ;4th digit is skipped 00004F57: LD B,06h 00004F59: CALL 4F6Ch ;xor crc for digits 5-10 00004F5C: LD HL,C91Bh 00004F5F: LD B,03h 00004F61: CALL 4F48h ;sum crc for digits 1-3 00004F64: INC HL ;4th digit is skipped 00004F65: LD B,06h 00004F67: CALL 4F48h ;sum crc for digits 5-10 00004F6A: JR -36h 00004F6C: RLCA ;crc left circular shift + xor subroutine 00004F6D: XOR (HL) 00004F6E: INC HL 00004F6F: DJNZ -05h 00004F71: RET